package cn.org.mrliu.code.generator.config;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ConfigUtil {
	private ConfigUtil() {
	}
	static{
		parse();
	}
	public static Config getConfig(){
		return Config.getInstance();
	}
	private static Properties getProperties() {
		InputStream inputStream = ConfigUtil.class.getClassLoader().getResourceAsStream("generator.properties");
		if (inputStream == null) {
			throw new RuntimeException("没有找到generator.properties配置文件");
		}
		Properties properties = new Properties();
		try {
			properties.load(inputStream);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("加载generator.properties配置文件错误");
		}
		return properties;
	}

	private static void parse() {
		Properties properties = getProperties();
		Config config = Config.getInstance();
		config.setDriverClass(properties.getProperty("driverClass", "com.mysql.jdbc.Driver"));
		config.setJdbcUrl(properties.getProperty("jdbcUrl"));
		config.setUserName(properties.getProperty("userName", "root"));
		config.setPassword(properties.getProperty("password", "root"));
		config.setTemplateDir(properties.getProperty("templateDir"));
	}

	public static void main(String[] args) throws FileNotFoundException {
		parse();
	}
}
